package org.example.springmybatisdemo.service;

import org.example.springmybatisdemo.entity.CarOrder;
import org.example.springmybatisdemo.entity.CarUser;
import org.example.springmybatisdemo.entity.Dept;
import org.example.springmybatisdemo.mapper.DeptMapper;
import org.example.springmybatisdemo.mapper.CarMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class CarServiceImpl  implements CarService {
    @Autowired
    private CarMapper carMapper;

    @Override
    public  List<CarUser> login(CarUser user) {
        List<CarUser> list = carMapper.queryByusernameAndPassword(user);
        System.out.println("user = " + list);
        if (list == null || list.isEmpty()) {
            System.out.println("user =1111 " + list);
            //            return null;
            throw new RuntimeException("用户名或密码错误");
        }
        return list;
    }

    public List<CarOrder> orderlist(Integer userId) {
        List<CarOrder> list = carMapper.SelectOrderList(userId);
        System.out.println("order = " + list);
        if (list == null || list.isEmpty()) {
            System.out.println("user =1111 " + list);
            //            return null;
            throw new RuntimeException("用户id不存在或没有数据");
        }
        return list;
    }

    public void addOrder(CarOrder carorder) {
        int affectedRows = carMapper.addOrder(carorder);

        if (affectedRows == 0) {
            throw new RuntimeException("添加失败,参数有误");
        }


//        List<CarOrder> list = carMapper.addOrder(carorder);
//        System.out.println("order = " + list);
//        if (list == null || list.isEmpty()) {
//            System.out.println("user =1111 " + list);
//            //            return null;
//            throw new RuntimeException("添加失败参数有误");
//        }
    }
}
